package ldh.msg.helper;

import java.util.Timer;
import java.util.TimerTask;

import ldh.msg.MsgConfigInfo;
import ldh.msg.contents.RecvMsgManager;
import ldh.msg.ui.MsgTrayManager;

public class TrayNotiTimer {

	static final String CLASS_NAME = "TrayNotiTimer";
	
	private Timer timer;
		
	public static TrayNotiTimer notiTimer = null; 
	
	private TrayNotiTimer() { 		
		try {
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static TrayNotiTimer getInstance() throws Exception {
		if (notiTimer == null) {
			synchronized (TrayNotiTimer.class) {
				notiTimer = new TrayNotiTimer();
			}
		}
		return notiTimer;
	}
	
	public void stopTimer() {
		if (this.timer != null) {
			this.timer.cancel();
		}
	}
	
	
	public void startTimer() {
		int interV = 0;
		try {
			interV = MsgConfigInfo.getInstance().getNotiInterV();
			if (interV != 0) {
				this.timer = new Timer(); 
				this.timer.scheduleAtFixedRate(new TrayNotiTask(), 0, interV * 60 * 1000);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	class TrayNotiTask extends TimerTask { 
		
		public TrayNotiTask() {
		}
	    public void run() { 
	    	try {	    		
		        System.out.println(" Noti Time!!! "); 
		        if (RecvMsgManager.unconfirmedMsgCnt == 0) return;
		        MsgTrayManager.getInstance().displayTrayNewMsg(RecvMsgManager.unconfirmedMsgCnt);
		        System.out.println(" Noti End!!! : ");
	    	} catch (Exception e) {
	    		e.printStackTrace();
	    	}
	    } 
	} 
}
